
<html>
<head>
<meta charset="UTF-8">
<title>数据表模型索引新增</title>
<link href="../../static/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css"/>
<link href="../../static/easyui/themes/icon.css" rel="stylesheet" type="text/css"/>
<link href="../../static/css/esaas-easyui-add.css" rel="stylesheet" type="text/css"/>
<script src="../../static/easyui/jquery.min.js" type="text/javascript"></script>
<script src="../../static/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../static/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
<script src="../../ffres/dict/all.js"></script>
<a href="" target="_blank" id="commonLink" name="commonLink"></a>
</head>
<body class="easyui-layout">
	<form id="ff" method="post">
		<div class="esaas-info-title">数据表模型索引信息</div>
		<table class="esaas-info-add-table">
			<tr>
				<td width="15%" align="right" hidden="true">对象标识：</td>
				<td width="35%" hidden="true"><input class="easyui-textbox" type="text"
					name="objectId" data-options="required:false" id="objectId"
					style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">索引名称：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					id="indexName" name="indexName" data-options="required:true"
					style="width: 100%; height: 25px;"></input></td>

				<td width="15%" align="right">主键索引：</td>
				<td width="35%"><input  type="checkbox" value="Y" id="indexTypePrimary"
					name="indexTypePrimary" data-options="required:false"></input>
				</td>
			</tr>
			<tr>
				<td width="15%" align="right">索引字段：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					id="indexFields" name="indexFields" data-options="required:false" readonly
					style="width: 85%; height: 25px;"></input>
					<a href="javascript:void(0)" class="easyui-linkbutton" onclick="openFieldModel()">选择</a>
				</td>
				<td width="15%" align="right">唯一索引：</td>
				<td width="35%"><input type="checkbox" value="Y" id="indexTypeUnique"
					name="indexTypeUnique" data-options="required:false"></input>
				</td>
			</tr>
			<tr>
				<td width="15%" align="right">索引描述：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="indexDesc" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr hidden="true">
				<td width="15%" align="right">创建人：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="createUser" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">创建时间：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="createTime" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr hidden="true">
				<td width="15%" align="right">最近修改用户：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="lastModifyUser" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">最近修改时间：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="lastModifyTime" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
			</tr>
		</table>
	</form>
	<div style="text-align: center; padding: 15px">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			onclick="submitForm()">&nbsp;保&nbsp;存&nbsp;</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			onclick="closeForm()">&nbsp;关&nbsp;闭&nbsp;</a>
	</div>
	<script>

		var objectId = $.getUrlParam('objectId');
		var index = $.getUrlParam('index');
		var tableInfo = null ;
		$(function() {
			$('#objectId').textbox('setValue', objectId);
			$.restfulGet('../../api/model/table/info/' + objectId,null,function(data){
				tableInfo = data.rows;		
				$('#indexName').textbox('setValue', `${tableInfo.objectCode}_index_${index*1 + 1}`)
			});

		});

		function submitForm() {
			if (!$('#ff').form('validate'))
				return;
			var jsonData = $("#ff").serializeJson();
			jsonData.indexTypePrimary = $('#indexTypePrimary').prop('checked') ? "Y" : "N";
			jsonData.indexTypeUnique = $('#indexTypeUnique').prop('checked') ? "Y" : "N";
			$.restfulPostJson('../../api/model/table/index', jsonData, function(data) {
				window.parent.reloadList();
			});
		};
		
		function closeForm() {
			window.parent.JLEUtil.closewin();
		}

		function openFieldModel() {
			JLEUtil.createModalWin('选择字段', 'popTableFieldChoice.html?' + 'objectId=' + objectId + '&callback=fieldCallback');
		}

		function fieldCallback(selections) {
			if (selections) {
				var fields = selections.map((field) => field.fieldCode );
				$('#indexFields').textbox('setValue', fields.join(","));
			}
		}
	</script>
</body>
</html>
